package com.itheima.user.service;

import com.itheima.cloud.Vo.UserOrderVo;
import com.itheima.cloud.pojo.Order;
import com.itheima.cloud.pojo.User;
import com.itheima.user.client.OrderClient;
import com.itheima.user.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    OrderClient orderClient;

    /**
     * 根据主键查询用户
     * @param id 用户id
     * @return 用户
     */
    public User queryById(Long id){
        return userMapper.selectByPrimaryKey(id);
    }


    public UserOrderVo findUserOrders(String username) {
        User user = userMapper.selectByPrimaryKey(username);

        UserOrderVo userOrderVo = new UserOrderVo();
        userOrderVo.setUser(user);

        List<Order> orderList = orderClient.findOrderByUserId(username);
        userOrderVo.setOrderList(orderList);

        return userOrderVo;
    }
}
